package com.example.demo.controller;

import com.example.demo.util.MsgMqUtil;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.boot.autoconfigure.jms.JmsProperties;
import org.springframework.http.ResponseEntity;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.jms.*;

/**
 * 业务聚合
 *
 * @version [V2.0]
 * @package com.example.demo.controller;
 * @description:[用一句话描述该文件做什么]
 * @author: [zhuben]
 * @date: [2021/7/15 21:18]
 * @copyright: 2021 echovin.com
 */

@RestController
@RequestMapping("active")
public class ActiveMqController {
    @Resource
    private JmsMessagingTemplate jmsMessagingTemplate;
    @GetMapping("send")
    public ResponseEntity<?> sendMessage() throws Exception {
        MsgMqUtil msgMqUtil = new MsgMqUtil(jmsMessagingTemplate, JmsProperties.AcknowledgeMode.AUTO.getMode(), DeliveryMode.NON_PERSISTENT, -1, 0L);
        boolean b = msgMqUtil.sendTopics("test", "测试封装");
        return b ? ResponseEntity.ok("success") : ResponseEntity.ok("fail");
    }


    @GetMapping("get")
    public ResponseEntity<?> getMessage() throws Exception{
        String test = new MsgMqUtil(jmsMessagingTemplate, JmsProperties.AcknowledgeMode.AUTO.getMode()).reviceMessage(new ActiveMQTopic("test"));
        return ResponseEntity.ok(test);
    }
}
